package xyz.xpman.prisonerfitness.common;

import android.annotation.SuppressLint;
import android.content.Context;

import org.jetbrains.annotations.NotNull;

import xyz.xpman.prisonerfitness.cache.AsyncImageLoader;
import xyz.xpman.prisonerfitness.config.AppConfig;
import xyz.xpman.prisonerfitness.entity.BaseModel;
import xyz.xpman.prisonerfitness.entity.Mappings;
import xyz.xpman.prisonerfitness.service.GroupRestTimeUtil;
import xyz.xpman.prisonerfitness.service.TrainingRecordService;
import xyz.xpman.prisonerfitness.service.TrainingThoughtsService;
import xyz.xpman.prisonerfitness.service.UserService;
import xyz.xpman.prisonerfitness.util.AppUtil;
import xyz.xpman.prisonerfitness.util.AssetsUtil;
import xyz.xpman.prisonerfitness.util.FileUtil;

public enum App {;

    private static Context appContext = null;

    @SuppressLint("NewApi")
    public static void init(@NotNull final Context context) {
        if (null != appContext) { return; }
        appContext = context;

        AppUtil.init(context);
        AppConfig.init(context);


        if (AppUtil.isFirstRun()) {
            // copy music in assert to app_data_path/file/prisonerfitness
            final String targetCacheDir = FileUtil.getFilesDirPath() + "/music";
            AssetsUtil.copyAssertDirToData(context, "music", targetCacheDir);
        }



        BaseModel.init(context);

        UserService.init(context);
        TrainingRecordService.init(context);
        TrainingThoughtsService.init(context);

        GroupRestTimeUtil.init(context);

        AsyncImageLoader.init();

        // 数据初始化
        Mappings.init(context);
    }


    @SuppressLint("NewApi")
    public static void destroy() {
        AsyncImageLoader.destroy();
    }


    public static Context getContext() {
        return appContext;
    }

}
